<template>
  <div id="container">
    <div class="itemlist">
      <el-form :model="form">
        <h3 class="title">测 试 管 理 系 统</h3>
        <el-form-item label="用户名" prop="username">
          <el-input v-model="form.username" type="text" placeholder="username"  clearable></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="form.password" type="password" placeholder="password" show-password  clearable></el-input>
        </el-form-item>
        <el-form-item class="lastitem">
          <el-button class="elbtn" type="" @click="reset">重置</el-button>
          <el-button class="elbtn" type="primary" @click="login">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
  name: "register",
  data() {
    return {
      form: {
        username: "",
        password: ""
      },
    };
  },
  methods: {
    async login() {
      const { data: res } = await this.$http.get("/api/user/login", {
        params: this.form
      })
      window.localStorage.setItem("userid", res.data[0].tester_id)
      if (res.meta.status == 200) {
        if (res.data[0].tester_username == "admin") {
          this.$message.success("登录成功");
          this.$router.push("/home")
        }
        else {
          this.$message.success("登录成功");
          this.$router.push("/thome")
        }
      }
      else {
        this.$message.error("登录失败");
      }
    },
    //重置方法
    reset() {
      var obj = {
        username: "",
        password: ""
      }
      this.form = obj
    }
  }
};
</script>
<style>
#container {
  background: url("~@/assets/bj.png");
  width: 100%;
  height: 100%;
  position: fixed;
  background-size: 100% 100%;
}
.itemlist {
  width: 400px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border: 1px solid rgb(146, 144, 144);
  border-radius: 16px;
  padding: 30px;
  opacity: 93%;
}
.el-textarea__inner,.el-input__inner{
    background: transparent;
  }
.lastitem {
  text-align: right;
  padding-right: 36px;
}
.title{
  font-size: 1.5em;
  color: #707070;
}
</style>